package com.ai.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ai.entity.SysDictEntity;
import com.ai.service.SysDictService;
import com.ai.web.PageResp;
import com.ai.web.request.SysDictAddReq;
import com.ai.web.request.SysDictPageReq;
import com.ai.web.request.SysDictUpdateReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 字典管理
 */
@Api(tags = "字典管理")
@RestController
@RequestMapping("/sysDict")
public class SysDictController {

    @Resource
    private SysDictService sysDictService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @SaCheckPermission("sysDict:add")
    public void add(@RequestBody SysDictAddReq sysDictAddReq) {
        sysDictService.save(sysDictAddReq);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    @SaCheckPermission("sysDict:delete")
    public void delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
        sysDictService.delete(ids);
    }

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    @SaCheckPermission("sysDict:update")
    public void update(@RequestBody SysDictUpdateReq sysDictUpdateReq) {
        sysDictService.updateById(sysDictUpdateReq);
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("/listByPage")
    @SaCheckPermission("sysDict:list")
    public PageResp<SysDictEntity> findListByPage(@RequestBody SysDictPageReq sysDictPageReq) {
        return sysDictService.page(sysDictPageReq);
    }

}
